package com.idreems.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.idreems.item.Item;
import com.idreems.model.JsonItem;
import com.viewpagerindicator.IconPagerAdapter;

public class CustomFragmentAdapter extends FragmentStatePagerAdapter// implements IconPagerAdapter
{
	protected static final int[] ICONS = new int[] {
	};

	private List<Item> mDataItemList = new ArrayList<Item>();
	private List<JsonItem> mJsonItemList = new ArrayList<JsonItem>();
	private Activity mActivityContext;
	
	public CustomFragmentAdapter(Activity activity,FragmentManager fm,List<Item> dataItemList)
	{
		super(fm);
		updateMenu(dataItemList);
		mActivityContext = activity;
	}

	/**
	 * 更新内容
	 * @param list
	 */
	public void updateContent(List<JsonItem> list)
	{
		mJsonItemList = list;
	}
	
	@Override
	public int getItemPosition(Object object)
	{
		return POSITION_NONE;
	}

	/**
	 * 更新索引相关数据
	 * @param dataItemList
	 */
	public void updateMenu(List<Item> dataItemList)
	{
		if (dataItemList == null)
		{
			return;
		}
		mDataItemList.clear();
		if (dataItemList.size() > 0)
		{
			mDataItemList.addAll(dataItemList);
		}
	}

	@Override
	public Fragment getItem(int position)
	{
		return SummaryListFragment.newInstance(mActivityContext,mJsonItemList);
	}

	@Override
	public int getCount()
	{
		return (mDataItemList==null)?0:mDataItemList.size();
	}

	@Override
	public CharSequence getPageTitle(int position)
	{
		return mDataItemList.get(position).mTitle;
	}

//	@Override
//	public int getIconResId(int index)
//	{
//		return ICONS[index % ICONS.length];
//	}
}